//
//  TopAlertView.m
//  testpbl
//
//  Created by 黄权浩 on 15/9/11.
//  Copyright (c) 2015年 黄权浩. All rights reserved.
//

#import "TopAlertView.h"

@implementation TopAlertView
{
@protected
    UIView *topView;
}

+ (instancetype)sharestand
{
    static TopAlertView *top = nil;
    static dispatch_once_t once;
    dispatch_once(&once,^{
        top = [[TopAlertView alloc] init];
    });
    return top;
}

- (void)initTopview:(NSString *)title withmisstime:(float)timer class:(id)nowclass
{
    if (!topView) {
        topView = [[UIView alloc] initWithFrame:CGRectMake(0, -64, [UIScreen mainScreen].bounds.size.width, 64)];
        topView.backgroundColor = [UIColor redColor];
        UILabel *alerttitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, topView.bounds.size.width, topView.bounds.size.width)];
        alerttitle.text = title;
        alerttitle.textColor = [UIColor whiteColor];
        alerttitle.font = [UIFont systemFontOfSize:10];
        alerttitle.textAlignment = NSTextAlignmentLeft;
        alerttitle.numberOfLines = 0;
        [topView addSubview:alerttitle];
        UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changethetextName:)];
        [topView addGestureRecognizer:gest];
        [nowclass addSubview:topView];
        [UIView animateWithDuration:1 animations:^{
            topView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 64);
        }];
    }else {
        
    }
    
    [self performSelector:@selector(missTopview) withObject:self afterDelay:timer];
}

- (void)changethetextName:(ChangeNSString)changeName
{
    changeName(@"111");
}

- (void)missTopview
{
    [UIView animateWithDuration:1 animations:^{
        topView.frame = CGRectMake(0, -64, [UIScreen mainScreen].bounds.size.width, 64);
    } completion:^(BOOL finished) {
        topView = nil;
    }];
}

@end
